//
//  TableSection.m
//  Portable Traffic Signal Assistor
//
//  Created by Hao Xu on 3/31/12.
//  Copyright (c) 2012 TTU. All rights reserved.
//



#import "TableSection.h"

@implementation TableSection


@synthesize contents=_contents;
@synthesize header=_header;
@synthesize footer=_footer;
@synthesize accessoryType=_accessoryType;

static UIFont *titleFont;
static UIColor *whiteColor;
static UIColor *selectionButtonBackGround;


-(id) init
{
    self=[super init];
    self.accessoryType=UITableViewCellAccessoryNone;
    return self;
}

-(void) dealloc
{
    
    [_contents release];
    [_header release];
    [_footer release];
    
    [super dealloc];
}

+ (UIFont*) TitleFont
{
    if (!titleFont) titleFont = [[UIFont boldSystemFontOfSize:CONST_textLabelFontSize] autorelease];
    return titleFont;
}

+ (CGFloat) calculateStringHeight:(NSString *)content
{
    CGSize titleSize;
    titleSize=[content sizeWithFont:[TableSection TitleFont] constrainedToSize:CGSizeMake(CONST_portraitCellWidth-2, 4000) lineBreakMode:NSLineBreakByWordWrapping];
    //CGFloat height=((NSInteger)titleSize.height)/;
    if (titleSize.height<CONST_Cell_height) {
        titleSize.height=CONST_Cell_height;
    }else
    {
        titleSize.height=titleSize.height+20;
    }
    return titleSize.height;
}

+ (CGFloat) calculatePopoverHeight:(NSArray *)listSections
{
    CGFloat height=0;
    for (int i=0; i<listSections.count; i++) {
        TableSection *section=[listSections objectAtIndex: i];
        height=height+CONST_section_header_height+section.contents.count*CONST_Cell_height;
        
    }
    height=height+CONST_section_header_height+20;
    return height;
}

+ (UIColor *) WhiteColor
{
    if(!whiteColor) whiteColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    
    return whiteColor;
}

+ (UIColor *) SelectionButtonBackground
{
    if(!selectionButtonBackGround) selectionButtonBackGround=[UIColor colorWithPatternImage:[UIImage imageNamed:@"dropdown.png"]];
    return selectionButtonBackGround;
}

+ (UIColor *) SelectionButtonBackgroundSmall
{
    if(!selectionButtonBackGround) selectionButtonBackGround=[UIColor colorWithPatternImage:[UIImage imageNamed:@"dropdown2.png"]];
    return selectionButtonBackGround;
}



@end

